Vue js Array fill() function : A value is added to a given array element using the fill() function. The fill() function takes the place of the initial array. The beginning and ending positions can be mentioned. All elements will be filled if not mentioned.In this example, we’ll show you how to use Vue.js’s fill() function to insert a value into a specific array. Try out our “run online” feature to see the results in real time.
Vue js Array fill with index
Vue js Array fill() first two index | Example
<div id="app" class="container">
<p>Language : {{language}}</p>
<button class="btn btn-primary" @click="myFunction">fill method</button>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data() {
return {
language :['HTML','CSS','Javascript','PHP','Vue','React'],
}
},
methods:{
myFunction(){
this.language.fill('Node','0','2');
}
}
}).mount('#app')
</script>
This is how the output from the previous example will appear:
Array fill all elements in vue js
Array fill() All index in Vue JS | Example
<div id="app" class="container">
<p>Language : {{language}}</p>
<button class="btn btn-primary" @click="myFunction">fill method</button>
</div>
<script type="module">
import { createApp } from 'vue'
createApp({
data() {
return {
language :['HTML','CSS','Javascript','PHP','Vue','React'],
}
},
methods:{
myFunction(){
this.language.fill('Express');
}
}
}).mount('#app')
</script>
This is how the output from the previous example will appear: